package sample.com.imagecompress;

import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.github.chrisbanes.photoview.PhotoView;

import java.util.ArrayList;
import java.util.List;

import sample.com.imagecompress.adapter.PhotoViewPagerAdapter;
import sample.com.imagecompress.widget.PhotoViewPager;

public class PhotoViewActivity extends AppCompatActivity {

    private PhotoView photoView;
//    private PhotoViewAttacher photoViewAttacher;

    private PhotoViewPager photoViewPager;
    private PhotoViewPagerAdapter photoViewPagerAdapter;

    private TextView page;

    private List<Uri> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_view);

        page = (TextView) findViewById(R.id.tv_page);

//        photoView = (PhotoView) findViewById(R.id.pv_photoView);
//        photoViewAttacher = new PhotoViewAttacher(photoView);
//        photoViewAttacher.update();

//        photoView.setOnViewTapListener(null);
//        photoView.setOnDoubleTapListener(null);

        photoViewPager = (PhotoViewPager) findViewById(R.id.photoViewPager);

        list = new ArrayList<>();

        Parcelable obj = getIntent().getParcelableExtra("PHOTO_PATH");
        if (obj != null) {
            Uri uri = (Uri) obj;
//            photoView.setImageURI(uri);
            list.add(uri);
            list.add(uri);
            list.add(uri);
        }

        photoViewPagerAdapter = new PhotoViewPagerAdapter(this, list);
        photoViewPager.setAdapter(photoViewPagerAdapter);

        page.setText(String.format("%d/%d", 1, list.size()));

        photoViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                page.setText(String.format("%d/%d", position + 1, list.size()));
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
